Conditions | 1 |
Paths | 1 |
Total Lines | 175 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | |||
66 | const sandcageWithWrongKey = new Sandcage({apiKey: WRONG_KEY}); |
||
67 | |||
68 | before('init nock', () => { |
||
69 | specHelper.initNock(); |
||
70 | }); |
||
71 | |||
72 | describe('getInfo', () => { |
||
73 | |||
74 | let response; |
||
75 | |||
76 | before('call getInfo', (done) => { |
||
77 | sandcage |
||
78 | .getInfo({'request_id': REQUEST_ID}, (err, result) => { |
||
79 | response = result; |
||
80 | done(); |
||
81 | }); |
||
82 | }); |
||
83 | |||
84 | it('should contain status', () => { |
||
85 | return expect(response.status).to.exist; |
||
86 | }); |
||
87 | |||
88 | it('status should be "success"', () => { |
||
89 | expect(response.status).to.be.equal('success'); |
||
90 | }); |
||
91 | |||
92 | it('files should be an array', () => { |
||
93 | expect(response.files).to.be.an('array'); |
||
94 | }); |
||
95 | }); |
||
96 | |||
97 | describe('getInfo with wrong key', () => { |
||
98 | |||
99 | let response; |
||
100 | |||
101 | before('call getInfo', (done) => { |
||
102 | sandcageWithWrongKey |
||
103 | .getInfo({'request_id': REQUEST_ID}, (err) => { |
||
104 | response = err; |
||
105 | done(); |
||
106 | }); |
||
107 | }); |
||
108 | |||
109 | it('should catch error', () => { |
||
110 | return expect(response).to.exist; |
||
111 | }); |
||
112 | }); |
||
113 | |||
114 | describe('listFiles', () => { |
||
115 | |||
116 | let response; |
||
117 | |||
118 | before('call listFiles', (done) => { |
||
119 | sandcage |
||
120 | .listFiles({directory: 'img/'}, (err, result) => { |
||
121 | response = result; |
||
122 | done(); |
||
123 | }); |
||
124 | }); |
||
125 | |||
126 | it('should contain status', () => { |
||
127 | return expect(response.status).to.exist; |
||
128 | }); |
||
129 | |||
130 | it('status should be "success"', () => { |
||
131 | expect(response.status).to.be.equal('success'); |
||
132 | }); |
||
133 | |||
134 | it('files should be an array', () => { |
||
135 | expect(response.files).to.be.an('array'); |
||
136 | }); |
||
137 | }); |
||
138 | |||
139 | describe('listFiles with wrong key', () => { |
||
140 | |||
141 | let response; |
||
142 | |||
143 | before('call listFiles', (done) => { |
||
144 | sandcageWithWrongKey |
||
145 | .listFiles({directory: 'img/'}, (err) => { |
||
146 | response = err; |
||
147 | done(); |
||
148 | }); |
||
149 | }); |
||
150 | |||
151 | it('should catch error', () => { |
||
152 | return expect(response).to.exist; |
||
153 | }); |
||
154 | }); |
||
155 | |||
156 | describe('scheduleTasks', () => { |
||
157 | |||
158 | let response; |
||
159 | |||
160 | before('call scheduleTasks', (done) => { |
||
161 | sandcage |
||
162 | .scheduleFiles({jobs: JOBS}, CALLBACK_URL, (err, result) => { |
||
163 | response = result; |
||
164 | done(); |
||
165 | }); |
||
166 | }); |
||
167 | |||
168 | it('should contain status', () => { |
||
169 | return expect(response.status).to.exist; |
||
170 | }); |
||
171 | |||
172 | it('status should be "success"', () => { |
||
173 | expect(response.status).to.be.equal('success'); |
||
174 | }); |
||
175 | |||
176 | it('tasks should be an array', () => { |
||
177 | expect(response.tasks).to.be.an('array'); |
||
178 | }); |
||
179 | }); |
||
180 | |||
181 | describe('scheduleTasks with wrong key', () => { |
||
182 | |||
183 | let response; |
||
184 | |||
185 | before('call scheduleTasks', (done) => { |
||
186 | sandcageWithWrongKey |
||
187 | .scheduleFiles({jobs: JOBS}, CALLBACK_URL, (err, result) => { |
||
188 | response = err; |
||
189 | done(); |
||
190 | }); |
||
191 | }); |
||
192 | |||
193 | it('should catch error', () => { |
||
194 | return expect(response).to.exist; |
||
195 | }); |
||
196 | }); |
||
197 | |||
198 | describe('destroyFiles', () => { |
||
199 | |||
200 | let response; |
||
201 | |||
202 | before('call destroyFiles', (done) => { |
||
203 | sandcage |
||
204 | .destroyFiles({files: FILES}, CALLBACK_URL, (err, result) => { |
||
205 | response = result; |
||
206 | done(); |
||
207 | }); |
||
208 | }); |
||
209 | |||
210 | it('should contain status', () => { |
||
211 | return expect(response.status).to.exist; |
||
212 | }); |
||
213 | |||
214 | it('status should be "success"', () => { |
||
215 | expect(response.status).to.be.equal('success'); |
||
216 | }); |
||
217 | |||
218 | }); |
||
219 | |||
220 | describe('destroyFiles with wrong key', () => { |
||
221 | |||
222 | let response; |
||
223 | |||
224 | before('call destroyFiles', (done) => { |
||
225 | sandcageWithWrongKey |
||
226 | .destroyFiles({files: FILES}, CALLBACK_URL, (err, result) => { |
||
227 | response = err; |
||
228 | done(); |
||
229 | }); |
||
230 | }); |
||
231 | |||
232 | it('should catch error', () => { |
||
233 | return expect(response).to.exist; |
||
234 | }); |
||
235 | }); |
||
236 | |||
237 | }); |
||
238 | |||
239 |